package testcase.app;


import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import api.app.Reportquery;
import common.Host;
import common.TestData;

/**
 * 帮忙医获取体检报告信息Reportquery接口测试用例
 * @author lipeng
 *
 */
public class TestReportquery
{
	/**
	 * 帮忙医获取体检报告信息Reportquery接口测试环境数据驱动
	 * @return
	 * @throws Exception
	 */
    @DataProvider(name="Test_adopt")
    public static String[][] testReportqueryDataProvider_adopt() throws Exception{
    	Host.setup("Test");
    	TestData td = new TestData("app/TestReportquery.xml");
    	return td.getParam("adopt");
    }
    
    /**
	 * 帮忙医获取体检报告信息Reportquery接口测试环境数据驱动
	 * @return
	 * @throws Exception
	 */
    @DataProvider(name="Test_adoptbaogao")
    public static String[][] testReportqueryDataProvider_adoptbaogao() throws Exception{
    	Host.setup("Test");
    	TestData td = new TestData("app/TestReportquery.xml");
    	return td.getParam("adoptbaogao");
    }
    
    /**
     * 帮忙医获取体检报告信息Reportquery接口用例
     * @param casename     --用例名称
     * @param parameter1   --卡号
     * @param parameter2   --密码
     * @param type         --类型
     * @param useId        --useid
     * @param isSearch
     * @param token        --token
     * @throws Exception
     */
    @Test(dataProvider="Test_adopt",groups={"Test"})
    public void testReportqueryTestCase(String casename,String parameter1,String parameter2,String type,String useId,String isSearch,String token)throws Exception{
    	//调用接口并将返回数据转换成json格式
    	String result = Reportquery.get(parameter1, parameter2, type, useId, isSearch, token);
    	JSONObject jsonResult;
    	if(result==null || result.isEmpty()){
    		jsonResult = null;
    	}
    	else {
			jsonResult = new JSONObject(result);
		}
    	
    	//设置检查点
    	switch (casename)
		{
			case "Success":
				Assert.assertFalse(jsonResult.getJSONArray("Data").isNull(0));
				break;
			case "Success1":
				Assert.assertFalse(jsonResult.getJSONArray("Data").isNull(0));
				break;

			default:
				break;
		}
    }
    
    /**
     * 帮忙医获取体检报告信息Reportquery接口用例
     * @param casename
     * @param studyid
     * @param flag
     * @param token
     * @throws Exception
     */
    @Test(dataProvider="Test_adoptbaogao",groups={"Test"})
    public void testReportqueryTestCase_adoptbaogao(String casename,String studyid,String flag,String token)throws Exception{
    	//调用接口并将返回数据转换成json格式
    	if(flag==null||flag.isEmpty())
    	   flag="null";
    	String result=Reportquery.get(studyid, flag, token);
    	JSONObject jsonResult;
    	if(result==null || result.isEmpty()){
    		jsonResult = null;
    	}
    	else {
			jsonResult = new JSONObject(result);
		}
    	
    	//设置检查点
    	switch (casename){
			case "Success":
				Assert.assertEquals(jsonResult.getJSONObject("Data").getString("StudyId"), "121703190054");
				break;
			default:
				break;
		}
    }
}
